// 存储请求函数模块
import request from '@/utils/request.js'
import store from '@/store'

// 登录接口
export const loginApi = (data) => {
  return request({
    url: '/user/login',
    method: 'POST',
    data
  })
}
// 获取个人信息
export const information = () => {
  return request({
    url: '/user',
    method: 'GET',
    headers: {
      authorization: store.state.token
    }
  })
}
// 首页轮播图
export const homeImg = () => {
  return request({
    url: '/home/swiper',
    method: 'GET'
  })
}
// 获取房屋查询条件
export const findInfo = (id) => {
  return request({
    url: '/houses/condition',
    params: {
      id
    }
  })
}
// 获取房源数据
export const Listing = (index) => {
  return request({
    url: '/area/map',
    method: 'GET',
    params: {
      id: index
    }
  })
}
// 获取城市列表数据
export const Lists = () => {
  return request({
    url: '/area/city',
    method: 'GET',
    params: {
      level: 1
    }
  })
}
// /houses/condition
export const condition = () => {
  return request({
    url: '/houses/condition',
    method: 'GET'

  })
}
// 根据条件查询房屋 /houses
export const houses = (i) => {
  return request({
    url: '/houses',
    method: 'GET',
    params: {
      cityId: i
    }
  })
}
// 租房小组
export const houseGroup = ({ area }) => {
  return request({
    url: '/home/groups',
    method: 'GET',
    params: {
      area: area

    }
  })
}
// 根据条件查询房屋
export const inquireHouses = ({
  cityId,
  area,
  subway,
  rentType,
  price,
  more,
  roomType,
  oriented,
  characteristic,
  floor,
  start,
  end
}) => {
  return request({
    url: '/houses',
    params: {
      cityId,
      area,
      subway,
      rentType,
      price,
      more,
      roomType,
      oriented,
      characteristic,
      floor,
      start,
      end

    }

  })
}
// 地图的接口 /area/map
export const mapApi = (id) => {
  return request({
    url: '/area/map',
    params: {
      id: id
    }
  })
}
// 获取子级城市列表
export const san = (id) => {
  return request({
    url: '/area',
    params: {
      id: id
    }
  })
}
// 查看收藏列表
export const CollectList = (authorization) => {
  return request({
    url: '/user/favorites',
    headers: {
      authorization: authorization
    }
  })
}
// /houses/{id} 查询房屋具体信息
export const specificApi = (id) => {
  return request({
    url: '/houses/' + id,
    path: {
      id
    }
  })
}
// 发布房源
export const issue = ({ title, description, houseImg, oriented, supporting, price, roomType, size, floor, community }) => {
  return request({
    url: '/user/houses',
    method: 'POST',
    headers: {
      Authorization: store.state.token
    },
    data: {
      title,
      description,
      houseImg,
      oriented,
      supporting,
      price,
      roomType,
      size,
      floor,
      community
    }
  })
}
// 小区关键词查询 搜索
export const search = ({ name, id }) => {
  return request({
    url: '/area/community',
    params: {
      name, id
    }

  })
}
// 上传图片
export const picApi = (file) => {
  return request({
    url: '/houses/image',
    method: 'POST',
    data: file
  })
}
// 已发布数据
export const PublishedApi = () => {
  return request({
    url: '/user/houses',
    headers: {
      Authorization: store.state.token
    }

  })
}
